package com.liu.ai.chat;

import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.ai.retry.RetryUtils;
import org.springframework.web.client.RestClient;
import org.springframework.web.reactive.function.client.WebClient;

@Slf4j
public class OpenaiChatDemo {

    private static final String apiKey = "sk-d1c41de66c074fc686488ab227d32fbe";


    public static void main(String[] args) throws InterruptedException {


        OpenAiApi dashScopeApi = new OpenAiApi(
                "https://dashscope.aliyuncs.com",
                apiKey,
                "/compatible-mode/v1/chat/completions",
                "/embedding",
                RestClient.builder(),
                WebClient.builder(),
                RetryUtils.DEFAULT_RESPONSE_ERROR_HANDLER
                );

        OpenAiChatModel chatModel = new OpenAiChatModel(dashScopeApi);
        OpenAiChatOptions options = OpenAiChatOptions.builder()
                .model("qwen-max")
                .build();
        ChatResponse res = ChatClient.builder(chatModel)
                .defaultOptions(options)
                .build()
                .prompt("介绍一下你自己")
                .call()
                .chatResponse();

        System.out.println(res);

        Thread.sleep(1000 * 60 * 40);
    }

}

